package config

import (
	"sync"

	"github.com/zeromicro/go-queue/kq"
	"github.com/zeromicro/go-zero/rest"
)

type Config struct {
	rest.RestConf
	JWT struct {
		AccessSecret string
	}
	DB struct {
		DataSource string
	}
	Redis RedisConf
	Minio Minio
	Kafka struct {
		Pusher   kq.KqConf
		Consumer kq.KqConf
	}
	Gorse Gorse
}

type BaseConfig struct {
	Consul ConsulConfig
	// 其他基础配置
}

type ConsulConfig struct {
	Host      string
	Key       string // 服务注册key
	ConfigKey string // 配置key
	Token     string
	TTL       int
}

type RedisConf struct {
	Host string
	Type string // `yaml:"Type" default:"node" options:"node|cluster"`
	Pass string // `yaml:"Pass,omitempty"`
	Tls  bool   // `yaml:"Tls,omitempty"`
}

// MinIO配置
type Minio struct {
	Endpoint   string
	AccessKey  string
	SecretKey  string
	UseSSL     bool
	BucketName string
}

type Gorse struct {
	Host   string
	ApiKey string
}

var (
	baseCfg BaseConfig
	once    sync.Once
)

// GetBaseConfig 返回已加载的基础配置
func GetBaseConfig() BaseConfig {
	return baseCfg
}

// SetBaseConfig 设置基础配置（供 main 函数调用）
func SetBaseConfig(cfg BaseConfig) {
	once.Do(func() {
		baseCfg = cfg
	})
}
